-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Flutter lint #253
Add Flutter lint #253
Conversation
408c287
to
0f457d3
Compare
852984c
to
0cba11a
Compare
e32b93e
to
317c607
Compare
0cba11a
to
d317e21
Compare
317c607
to
a2f61a8
Compare
a2f61a8
to
8a3f628
Compare
import 'package:mobile_nebula/services/theme.dart'; | ||
import 'package:mobile_nebula/services/utils.dart'; | ||
import 'package:sentry_flutter/sentry_flutter.dart'; | ||
|
||
Future<void> main() async { | ||
usePathUrlStrategy(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to git blame (https://github.com/DefinedNet/mobile_nebula/blame/bcfcadec8ef46f2ed628ab9334088e1f142f22a6/lib/main.dart#L18), this was added as part of the work to support DN enrollment. We need to be able to process a url deep-link when enrolling, so I do not think we can remove this package or this line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW I think this is the only real blocker here. (And maybe the concatenation one, depending on whether that format actually works or not in dart.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iOS at least works with this removed, the correct page is opened.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe https://github.com/stryder-dev/flutter_platform_widgets/wiki/Routing may handle this instead, not requiring importing an un-exported function.
Lines 92 to 126 in bcfcade
(context) => PlatformApp( | |
debugShowCheckedModeBanner: false, | |
localizationsDelegates: <LocalizationsDelegate<dynamic>>[ | |
DefaultMaterialLocalizations.delegate, | |
DefaultWidgetsLocalizations.delegate, | |
DefaultCupertinoLocalizations.delegate, | |
], | |
title: 'Nebula', | |
material: (_, __) { | |
return new MaterialAppData( | |
themeMode: brightness == Brightness.light ? ThemeMode.light : ThemeMode.dark, | |
theme: brightness == Brightness.light ? theme.light() : theme.dark(), | |
); | |
}, | |
cupertino: (_, __) => CupertinoAppData(theme: CupertinoThemeData(brightness: brightness)), | |
onGenerateRoute: (settings) { | |
if (settings.name == '/') { | |
return platformPageRoute(context: context, builder: (context) => MainScreen(this.dnEnrolled)); | |
} | |
final uri = Uri.parse(settings.name!); | |
if (uri.path == EnrollmentScreen.routeName) { | |
// TODO: maybe implement this as a dialog instead of a page, you can stack multiple enrollment screens which is annoying in dev | |
return platformPageRoute( | |
context: context, | |
builder: | |
(context) => | |
EnrollmentScreen(code: EnrollmentScreen.parseCode(settings.name!), stream: this.dnEnrolled), | |
); | |
} | |
return null; | |
}, | |
), | |
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by "importing an un-exported function"? What is being done here is what the docs show: https://docs.flutter.dev/ui/navigation/url-strategies#configuring-the-url-strategy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trying to get my android emulator to work for testing...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by "importing an un-exported function"? What is being done here is what the docs show: docs.flutter.dev/ui/navigation/url-strategies#configuring-the-url-strategy
We needed to add the package as a direct dependency, rather than indirectly importing it as part of the flutter sdk.

Added that dep to pubspec.yaml and everything's all good now.
lib/services/theme.dart
Outdated
@@ -11,51 +11,51 @@ class MaterialTheme { | |||
static ColorScheme lightScheme() { | |||
return const ColorScheme( | |||
brightness: Brightness.light, | |||
primary: Color(4284700303), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should ignore this file, since it was auto-generated and it will be easier to compare changes in the future if we don't muck around with it too much.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
lib/services/utils.dart
Outdated
@@ -41,10 +41,10 @@ class Utils { | |||
|
|||
static String itemCountFormat(int items, {singleSuffix = "item", multiSuffix = "items"}) { | |||
if (items == 1) { | |||
return items.toString() + " " + singleSuffix; | |||
return "$items " + singleSuffix; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still using concatenation, and does it need to be ${items}
? (same below)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, this syntax works ${...}
syntax is only needed for complex expressions, so ${items+1}
v.s.$items
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, but, shouldn't this still be `${items} ${singleSuffix}`?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, whoops forgot to actually augment the autofix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❯ jj absorb
Absorbed changes into these revisions:
povmpvpx 93f7cc15 `dart fix --apply --code=prefer_interpolation_to_compose_strings`
Rebased 10 descendant commits.
Working copy now at: wusutqos b0d3d23d (no description set)
Parent commit : pxwtotsz 05879848 flutter-lint* | `dart format lib/`
Remaining changes:
M lib/services/utils.dart
Love that I can use jj absorb
to automatically include the fix in the associated commit it should have been in. Works 70% of the time 100% of the time!
@@ -11,7 +11,7 @@ bool DEFAULT_TRACK_ERRORS = true; | |||
class Settings { | |||
final _storage = Storage(); | |||
final StreamController _change = StreamController.broadcast(); | |||
var _settings = Map<String, dynamic>(); | |||
var _settings = <String, dynamic>{}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a huge fan of this rule, seems stylistic and more obtuse, but if that's the recommended way, I guess we can roll with it. Just seems like there's no good reason not to be explicit. /shrug
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll leave it enabled. not a fan, but i like keeping the config to a min over customizing.
Add https://pub.dev/packages/flutter_lints and fix the complaining lints
See https://dart.dev/tools/analysis#lints for more
This surfaced two package imports that weren't tracked by pubspec.yaml:
path
was imported w/o being registered as a dep, andflutter_web_plugins
, an internal tool of Flutter, was being imported, and needed a manually added dependency.